﻿<%
_out.targetFile =  util.format('%s\\Infrastructure\\EntityFramework\\%sUnitOfWork.Generator.cs', serverProjectDirectory, module);
%>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.Entity;
using System.ComponentModel.DataAnnotations.Schema;

using Happy.Infrastructure.EntityFramework;
using <%= rootNamespace %>.Domain;
<% 
_.each(aggregates, function(aggregate, index) { 
%>
using <%= rootNamespace %>.Domain.<%= aggregate.plural %>;
<%
});
%>

namespace <%= rootNamespace %>.Infrastructure.EntityFramework
{
    internal sealed partial class <%= module %>UnitOfWork : UnitOfWork, I<%= module %>UnitOfWork
    {
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            this.BeforeModelCreating(modelBuilder);
<% 
_.each(aggregates, function(aggregate, index) { 
%>

            modelBuilder
                .Entity<<%= aggregate.singular %>>()
                .HasKey(x => x.Id);
            modelBuilder
                .Entity<<%= aggregate.singular %>>()
                .Property(x => x.OptimisticKey)
                .IsRowVersion();
            modelBuilder
                .Entity<<%= aggregate.singular %>>()
                .Property(x => x.IsDeleted);
            this.On<%= aggregate.singular %>Creating(modelBuilder);
<%
});
%>
        }

        partial void BeforeModelCreating(DbModelBuilder modelBuilder);
<% 
_.each(aggregates, function(aggregate, index) { 
%>

        partial void On<%= aggregate.singular %>Creating(DbModelBuilder modelBuilder);
<%
});
%>
    }
}